<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="keywords" content="Piece,统一登录平台,首页">
    <meta name="description" content="Piece统一登录平台首页">
    <meta name="author" content="Piece"/>
    <title>Piece | Dashboard</title>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <link th:href="@{/lib/bootstrap/bootstrap.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/lib/font-awesome/css/font-awesome.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/animate.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/style.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/skins.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/custom.css?v=1.0.0}" rel="stylesheet" type="text/css"/>
    <!-- Icons -->
    <link rel="apple-touch-icon" type="text/html" sizes="76x76" th:href="@{/image/apple-icon.png}"/>
    <link rel="shortcut icon" type="text/html" sizes="96x96" th:href="@{/image/favicon.png}"/>

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script th:src="@{/lib/html5shiv.min.js}"></script>
    <script th:src="@{/lib/respond.min.js}"></script>
    <![endif]-->

    <style type="text/css">
        body {
            height: 100%;
            overflow: hidden;
        }
        #content-main.max {
            height: calc(100% - 110px);
            overflow: hidden;
            width: 100%;
            height: 100%;
            left: 0px;
            position: absolute;
            top: 0px;
            z-index: 9999;
            margin: 0;
        }
        input::-webkit-input-placeholder {
            color: grey;
        }
    </style>

    <script type=”text/javascript”>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg skin-blue">
<div id="wrapper">

    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close">
            <i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li class="nav-header">
                    <div>
                        <span class="logo-expanded">
                            <img th:src="@{/image/logo@2x.png}" width="80"/>
                        </span>
                        <span class="logo-collapsed">
                            <img th:src="@{/image/logo-collapsed@2x.png}" width="50"/>
                        </span>
                    </div>
                </li>
                <li class="active">
                    <a th:href="@{/api/home}" class="menuItem menuClick"><i class="fa fa-home"></i> <span class="nav-label">Dashboard</span></a>
                </li>
                <li th:each="menu : ${menus}">
                    <a th:class="${not #lists.isEmpty(menu.children)} ? |menuItem menuClick| : ''">
                        <i class="fa fa-bar-chart-o" th:class="${menu.icon}"></i>
                        <span class="nav-label" th:text="${menu.menuName}">一级菜单</span>
                        <span th:class="${not #lists.isEmpty(menu.children)} ? |fa arrow|"></span>
                    </a>
                    <ul class="nav nav-second-level collapse">
                        <li th:each="cmenu : ${menu.children}">
                            <a th:if="${#lists.isEmpty(cmenu.children)}" th:class="${not #strings.isEmpty(cmenu.path)} ? |menuItem menuClick| : ${cmenu.target}" th:utext="${cmenu.menuName}" th:target="${cmenu.target}" th:href="@{${cmenu.path}}">二级菜单</a>
                            <a th:if="${not #lists.isEmpty(cmenu.children)}" href="#">[[${cmenu.menuName}]]<span class="fa arrow"></span></a>
                            <ul th:if="${not #lists.isEmpty(cmenu.children)}" class="nav nav-third-level">
                                <li th:each="emenu : ${cmenu.children}">
                                    <a th:if="${#lists.isEmpty(emenu.children)}" th:class="${not #strings.isEmpty(emenu.path)} ? |menuItem menuClick| : ${emenu.target}" th:text="${emenu.menuName}" th:target="${emenu.target}" th:href="@{${emenu.path}}">三级菜单</a>
                                    <a th:if="${not #lists.isEmpty(emenu.children)}" href="#">[[${emenu.menuName}]]<span class="fa arrow"></span></a>
                                    <ul th:if="${not #lists.isEmpty(emenu.children)}" class="nav nav-four-level">
                                        <li th:each="fmenu : ${emenu.children}"><a th:if="${#lists.isEmpty(fmenu.children)}" th:class="${not #strings.isEmpty(fmenu.path)} ? |menuItem menuClick| : ${fmenu.target}" th:text="${fmenu.menuName}" th:target="${emenu.target}" th:href="@{${fmenu.path}}">四级菜单</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li th:if="${demoEnabled}">
                    <a href="#"><i class="fa fa-desktop"></i><span class="nav-label">用例演示</span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li>
                            <a>表格<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/table/curd}">高级表格</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/table/fixedColumns}">表格冻结列</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/table/groupHeader}">组合表头</a></li>
                            </ul>
                        </li>
                        <li>
                            <a>表单<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/button}">按钮</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/grid}">栅格</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/select}">下拉框</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/basic}">基本表单</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/autocomplete}">搜索自动补全</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/datetime}">日期和时间</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/upload}">文件上传</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/duallistbox}">左右互选组件</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/wizard}">表单向导</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/tabs_panels}">选项卡 & 面板</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/sortable}">拖动排序</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/form/jasny}">功能扩展</a></li>
                            </ul>
                        </li>
                        <li>
                            <a>弹框<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/modal/dialog}">模态窗口</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/modal/layer}">弹层组件</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/modal/table}">弹层表格</a></li>
                            </ul>
                        </li>
                        <li>
                            <a>报表<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/report/echarts}">百度ECharts</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/report/peity}">peity</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/report/sparkline}">sparkline</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/report/metrics}">图表组合</a></li>
                            </ul>
                        </li>
                        <li>
                            <a>图标<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/icon/fontawesome}" target="blank">Font Awesome</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/api/demo/icon/glyphicons}" target="blank">Glyphicons</a></li>
                            </ul>
                        </li>
                        <li>
                            <a>错误页面<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li><a class="menuItem menuClick" th:href="@{/error/403}">403</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/error/404}">404</a></li>
                                <li><a class="menuItem menuClick" th:href="@{/error/500}">500</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->

    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2" href="#">
                        <i class="fa fa-bars"></i>
                    </a>
                    <form role="search" onsubmit="return false" class="navbar-form-custom" action="#">
                        <div class="form-group">
                            <input type="text" name="keyword" class="form-control search-field" th:placeholder="#{view.search}" />
                        </div>
                    </form>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="dropdown welcome-message">
                        <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
                            <i class="fa fa-envelope"></i>
                            <span class="label label-warning" id="message_title">[[${total}]]</span>[[#{view.message}]]
                        </a>
                        <ul class="dropdown-menu dropdown-messages" id="message_receive">
                            <li>
                                <div class="text-center link-block">
                                    <a href="#" onclick="showMessage()">
                                        <i class="fa fa-envelope"></i><strong>[[#{view.message.all}]]</strong>
                                    </a>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown dropdown-language">
                        <a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" href="#">
                            <span class="hidden-xs">
                                <th:block th:utext="#{view.language}"></th:block><i class="fa fa-chevron-down"></i>
                            </span>
                        </a>
                        <ul class="dropdown-menu">
                            <li class="mt5"><a th:href="@{/api/index?Language=zh_CN}">中文</a></li>
                            <li class="mt5"><a th:href="@{/api/index?Language=en_US}">English</a></li>
                        </ul>
                    </li>
                    <li class="dropdown user-menu">
                        <a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" href="#">
                            <img th:src="(${#strings.isEmpty(user.avatar)}) ? @{/image/avatar.png} : @{/api/file/preview/} + ${user.avatar}" class="user-image">
                            <span class="hidden-xs">[[${user.userName}]]</span>
                        </a>
                        <ul class="dropdown-menu">
                            <li class="mt5">
                                <a onclick="personal()">
                                    <i class="fa fa-user"></i> [[#{view.user.info}]]
                                </a>
                            </li>
                            <li>
                                <a onclick="resetPwd()">
                                    <i class="fa fa-key"></i> [[#{view.password.modify}]]
                                </a>
                            </li>
                            <li>
                                <a id="fullScreen">
                                    <i class="fa fa-arrows-alt"></i> [[#{view.fullscreen}]]
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a th:href="@{/logout?targetUrl=/authentication/login}">
                                    <i class="fa fa-sign-out"></i> [[#{view.logout}]]
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>

        <div th:replace="/common/tab :: tab(${singlePage})"></div>

        <div class="row mainContent" id="content-main">
            <iframe class="iframe_index" name="iframe0" width="100%" height="100%"
                    data-id="/api/home" th:src="@{/api/home}" frameborder="0" seamless></iframe>
        </div>

        <div class="footer fixed">
            <div class="pull-right">© [[#{view.copyright}]] [[#{view.title}]] All Rights Reserved.</div>
        </div>
    </div>
    <!--右侧部分结束-->
</div>

<div class="page-loading-overlay loaded">
    <div class="loader"></div>
</div>

<script type="text/javascript"> var ctx = [[${ctx}]]; var singlePage = [[${singlePage}]];</script>
<!-- 全局js -->
<script th:src="@{/lib/jquery/jquery.min.js?v=2.1.4}" type="text/javascript"></script>
<script th:src="@{/lib/bootstrap/bootstrap.min.js?v=3.3.5}" type="text/javascript"></script>
<script th:src="@{/lib/bootstrap/bootstrap-hover-dropdown.js}" type="text/javascript"></script>
<script th:src="@{/lib/metisMenu/jquery.metisMenu.js}"></script>
<script th:src="@{/lib/slimscroll/jquery.slimscroll.min.js}"></script>
<script th:src="@{/lib/fullscreen/jquery.fullscreen.js}"></script>
<script th:src="@{/lib/layui/layui.js}"></script>
<script th:src="@{/lib/socket/sockjs.min.js}"></script>
<script th:src="@{/lib/socket/stomp.min.js}"></script>
<script th:src="@{/js/aaa.js?v=1.0.0}"></script>
<script th:src="@{/js/api.js?v=1.0.0}"></script>

<script th:inline="javascript">
    var userId = [[${user.userId}]];
    var origin = [[${origin}]];
    var stompClient = null;

    $(function () {
        // 定时收取系统信息
        //receiveMessage();
        //window.onunload = closeSocket;
    });

    function receiveMessage() {
        $.ajax({
            url: ctx + 'api/websocket/startPollMessage',
            type: 'get',
            data: {
                type: 'message',
                size: 10
            },
            dataType: 'json',
            success: function (result) {
                if (result.code == 200) {
                    openSocket();
                }
            }
        });
    }

    function openSocket() {
        if (stompClient == null) {
            var socket = new SockJS(origin + '/api/stomp');
            //使用STMOP子协议的WebSocket客户端
            stompClient = Stomp.over(socket);
            //连接WebSocket服务端
            stompClient.connect({}, function(frame) {
                stompClient.subscribe('/user/' + userId + '/queue/getMessage', function(event) {
                    var content = JSON.parse(event.body);
                    var html = '', url = '', size = 0;
                    $('li[name="message_receive"]').remove();
                    if (content) {
                        html = '';
                        $.each(content, function(index, message) {
                            url = '<a href="#" onclick="readMessage(\'' + message.messageId + '\')"><small>' + message.title + '</small></a>';
                            html += '<li id="' + message.messageId + '" class="m-t-xs" name="message_receive">' +
                                '<div class="dropdown-messages-box">' +
                                '<a class="pull-left"> <i class="fa fa-server"></i></a>' +
                                '<div class="media-body">' +
                                '<small class="pull-right">' + message.timeBefore + '</small><span style="font-size: 12px">' + url + '</span><br>' +
                                '<small class="text-muted"></small>' +
                                '</div></div><div class="divider"></div></li>';
                            size++;
                        });
                        $('#message_receive').find('li').eq(0).before(html);
                    }

                    $('#message_title').text(size);
                });
            });
        }
    }

    function stopPoll() {
        $.operate.get({
            url: ctx + 'api/websocket/stopPollMessage',
            success: function(result) {

            }
        });
    }

    function closeSocket() {
        stopPoll();

        if (stompClient != null) {
            stompClient.disconnect();
            stompClient = null;
        }
    }

    function resetPwd() {
        layer.open({
            title: [[#{view.password.modify}]],
            content: ctx + 'api/system/user/updatePwd?id=' + userId,
            area: ['100%', '75%'],
            type: 2,
            maxmin: false,
            anim: 1,
            fix: false,
            shade: 0.3
        });
    }

    function personal() {
        layer.open({
            title: [[#{view.user.info}]],
            content: ctx + 'api/system/user/profile?id=' + userId,
            area: ['100%', '90%'],
            type: 2,
            maxmin: false,
            anim: 1,
            fix: false,
            shade: 0.3,
            shadeClose: true
        });
    }

    function readMessage(messageId) {
        console.log('message_id:' + messageId);
    }

    function showMessage() {
        //$('li[name="message_receive"]').remove();
        //$('#message_title').text('0');
    }
</script>
</body>
</html>
